package com.alphasta.project.system.ncp.service;

import com.alphasta.common.utils.JsonUtil;
import com.alphasta.framework.shiro.web.filter.LogoutFilter;
import com.alphasta.project.system.ncp.entity.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;
import java.util.List;

/**
 * 可能密切接触者 服务层 处理
 * @author 孟凡超
 *
 */
@Service
public class SuspectedPersonServiceImpl implements SuspectedPersonService {
    private static final Logger log = LoggerFactory.getLogger(LogoutFilter.class);
    @Value("${qqjg.qqjgdm}")
    private String qqjgdm;// 请求机构代码,
    @Value("${qqjg.qqjgmc}")
    private String qqjgmc;// 请求机构名称,
    @Value("${ncp.suspectedPersonUrl}")
    private String suspectedPersonUrl;
    @Value("${ncp.contentType}")
    private String contentType;
    @Value("${ncp.processNum}")
    private String processNum;
    @Value("${ncp.stepNum}")
    private String stepNum;
    @Value("${ncp.receiveAppId}")
    private String receiveAppId;
    @Value("${ncp.invokingAppId}")
    private String invokingAppId;
    @Value("${ncp.apiKey}")
    private String apiKey;
    @Value("${ncp.secretKey}")
    private String secretKey;
    @Value("${ncp.topicCode}")
    private String topicCode;
    @Override
    public SuspectedPersonVO suspectedPerson(SuspectedPersonFrom suspectedPersonFrom) {

        SuspectedPersonVO suspectedPersonVO=new SuspectedPersonVO();
        HttpHeaders requestHeaders = new HttpHeaders();
        requestHeaders.add("Content-Type", contentType);
        requestHeaders.add("processNum", processNum);
        requestHeaders.add("stepNum", stepNum);
        requestHeaders.add("receiveAppId", receiveAppId);
        requestHeaders.add("invokingAppId", invokingAppId);
        //获取token
    /*    String token= GetToken.getToken();
        log.info("获取到的token="+token);
        requestHeaders.add("access_token", token);*/
//body
        MultiValueMap<String, String> requestBody = new LinkedMultiValueMap<>();
        requestBody.add("apiKey", apiKey);
        requestBody.add("secretKey", secretKey);
        requestBody.add("topicCode", topicCode);

        requestBody.add("cxsy", suspectedPersonFrom.getCxsy());
        requestBody.add("qqjgdm", qqjgdm);
        requestBody.add("qqjgmc", qqjgmc);
        requestBody.add("qqr", suspectedPersonFrom.getQqr());
        requestBody.add("qqrsfzhm", suspectedPersonFrom.getQqrsfzhm());
        requestBody.add("sfzhm", suspectedPersonFrom.getSfzhm());
        requestBody.add("xm", suspectedPersonFrom.getXm());
//HttpEntity
        HttpEntity<MultiValueMap<String,String>> requestEntity=new HttpEntity<MultiValueMap<String,String>>(requestBody, requestHeaders);
        RestTemplate restTemplate = new RestTemplate();
//post
        ResponseEntity<String> responseEntity = restTemplate.postForEntity(suspectedPersonUrl, requestEntity, String.class);
        suspectedPersonVO= JsonUtil.jsonToPojo(responseEntity.getBody(),SuspectedPersonVO.class);
        return suspectedPersonVO;
    }

}
